/**
 * 屏蔽鼠标右键
 */
function oncontextmenu(){
	event.returnValue=false;
}
//document.oncontextmenu=oncontextmenu;

//换肤
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};


window.onerror = function (){
	return true;
};

jQuery(function(){
	$(".change_skin").click(function(){
		//换css
		var skin = $(this).attr('id');
		$("#skincss").attr("href","resource/styles/"+skin+"/main.css");
		$("#skincss1").attr("href","resource/styles/"+skin+"/menu/menu.css");
		$("#skincss2").attr("href","resource/styles/"+skin+"/main.css");
		$("#skincss3").attr("href","resource/styles/"+skin+"/drag/inettuts.css");
		$("#skincss4").attr("href","../resource/styles/"+skin+"/detail.css");
		
		$.cookie("skin",skin,{path:"/",expires: 365});	
		//白框
		var this_class = $(this).attr('class');
		$(".c1on").removeClass('c1on').addClass("c1");
		$(".c2on").removeClass('c2on').addClass("c2");
		$(".c3on").removeClass('c3on').addClass("c3");
		$(".c4on").removeClass('c4on').addClass("c4");
		$(".c5on").removeClass('c5on').addClass("c5");
		if(this_class.indexOf("c1")>=0) $(this).removeClass('a1').addClass('c1on');
		if(this_class.indexOf("c2")>=0) $(this).removeClass('a2').addClass('c2on');
		if(this_class.indexOf("c3")>=0) $(this).removeClass('a3').addClass('c3on');
		if(this_class.indexOf("c4")>=0) $(this).removeClass('a4').addClass('c4on');
		if(this_class.indexOf("c5")>=0) $(this).removeClass('a5').addClass('c5on');
	
		//刷新子iframe
		document.getElementById('tranFrame').contentWindow.location.reload();
	});
	//白框
	var cur_skin = $.cookie("skin")? $.cookie("skin"):"default";
	if(cur_skin == "orange") $('.c2').removeClass('c2').addClass('c2on');
	if(cur_skin == "green") $('.c3').removeClass('c3').addClass('c3on');
	if(cur_skin == "red") $('.c4').removeClass('c4').addClass('c4on');
	if(cur_skin == "red") $('.c5').removeClass('c5').addClass('c5on');
});


/**
* 检验字符串是否为空
* @param {String} 字符串
* @return {bool} 是否为空
*/
function isEmpty(input)
{
	if( input==null ||  trim(input).length == 0 || input == 'null')
		return true;
	else
		return false;
}

/**
* 去掉字符串前后的空格
* @param {String} 字符串
* @return {String} 去除空格后的字符串
*/
function trim(input) {
	return input.replace(/(^\s*)|(\s*$)/g, "");
}

/**
* 若为null则替换为指定的字符串
* @param {String} 要测试的字符串
* @param {String} 为空时替换的字符串
* @return {String} 
*/
function nvl(s,replaceString)
{
	if ( isEmpty(s) )
		return replaceString;
	else
		return s;
} 

/**
* 取得指定的radio按钮的选中值
* @param {String} radio按钮ID
* @return {String} radio按钮的选中值
*/
function getRadioValue(radioId)
{	
	var radioList = document.getElementsByName(radioId);
	for (var i = 0; i < radioList.length; i++)
	{
		if( radioList[i].checked == true )
		{
			return radioList[i].value;
		}
	}
}
/**
 *设置单选框选中状态，根据参数值找出值与之相等的radio，并置为选中状态
 *@param radioId{String} radio名称
 *@param value {String} 需要找出的radio的值
 */
function setRadioValue(radioId, value) {
	var radioList = document.getElementsByName(radioId);
	if(radioList.length) {
		for (var i = 0; i < radioList.length; i++)
		{
			radioList[i].checked = radioList[i].value == value;
		}
	}else {
		radioList.checked = radioList.value == value;
	}
}

/**
* 检查字符串是否是整数
* @param {String} 字符串
* @return {bool} 是否是整数
*/
function isInteger( s )
{ 
	var isInteger = RegExp(/^[0-9]+$/);
	return ( isInteger.test(s) );
}

/*
 * 根据json数据生成输入表单用的html
 * 示例：getInputHtmlFromJson({name:'value'},i) = '<input type="hidden" name="formList[i].name" value="value" id="name"/>'
 * @param {json} jsonInput
 * @param {String} input的formList
 * @return {String} 生成的html 
 */
function getInputHtmlFromJson( jsonInput, i )
{
	var resultHtml = '';
	var prefixString ='<input type="hidden" name="formList[';
	for (var key in jsonInput ) 
	{
		var value = jsonInput[key];
		resultHtml += prefixString + i + '].'+ key +'" value="'+value+'"' + 'id="' + key + '"/>';
	}
	return resultHtml;
}

function getInputHtmlToJson(inputArray){
	var totalNumber = inputArray.length;
	var params = new Array();
	for( var i=0; i<totalNumber; i++ )
	{
		var jsonInput = inputArray[i];
		for (var key in jsonInput )
		{
			var value = jsonInput[key];
			params.push('"formList['+i+'].'+key+'":"'+value+'"'); 
		}
	}
	var size = params.length;
	var strParams = '{';
	for(var j=0; j<size; j++){
		if(j==size-1){
			strParams = strParams+params[j];
		}else{
		   strParams = strParams+params[j]+','; 
		}
	}
	strParams = strParams+'}';
	return jQuery.parseJSON(strParams);
}


/**
* 判断当前用户是否在使用Firefox浏览器
*/
function isFirefox(){
       if(window.navigator.userAgent.indexOf("Firefox")>=1)
           return true;
       else
           return false;
}

/**
* update frame height,the minimum heigth is 500 px
*/
function sizeChange() {
	try{
		var iframe = document.getElementById('tranFrame');
		var bHeight = iframe.contentWindow.document.body.scrollHeight;
		var dHeight = iframe.contentWindow.document.documentElement.scrollHeight;
		var bodyScrollHeight2;
		if(bHeight==0){
			bodyScrollHeight2=Math.max(bHeight, dHeight);
		}else{
			bodyScrollHeight2 = Math.min(bHeight, dHeight);
		}
				
	//	alert("bHeight:"+bHeight+"dHeight:"+dHeight+"bodyScrollHeight2:"+bodyScrollHeight2)
		var bodyScrollHeight = (bodyScrollHeight2 > 500) ? bodyScrollHeight2 : 500;
		
		//if(bodyScrollHeight>500){
			//bodyScrollHeight = bodyScrollHeight + 10;
		//}

		document.getElementById('tranFrame').height = bodyScrollHeight; 

		if(isFirefox()){
			var bodyScrollWidth=  document.getElementById("Page_content").offsetWidth;
			document.getElementById("tranFrame") .width = bodyScrollWidth;
		}
	}catch(e){
		//alert(e);
	}
}

/**
* 检查字符串是否是整数
* @param {String} 字符串
* @return {bool} 是否是整数
*/
function isInteger( s )
{ 
	var isInteger = RegExp(/^[0-9]+$/);
	return ( isInteger.test(s) );
}

/**
* 判断输入变量是否是实数
* @param {String} 要检查的变量值
* @return {bool} 是否为实数
*/
function isDecimal( s )
{
	var isDecimal = RegExp(/^([0-9]+(\.?))?[0-9]+$/);
	return ( isDecimal.test(s) );
}

/**
* 判断输入变量是否是数字或者字母
* @param {String} 要检查的变量值
* @return {bool} 是否为数字或者字母
*/
function isIntChar( s )
{
 	var isIntChar = RegExp(/^[a-zA-Z0-9]+$/);
	return ( isIntChar.test(s) );
 }

/**
* 判断输入变量是否是数字或者字母或者特殊字符
* 特殊字符：|_ - * & % $ # @ ! ~ ^ ( )
* @param {String} 要检查的变量值
* @return {bool} 是否为数字或者字母或者特殊字符
*/
function isIntCharSpecial( s )
{
	var isIntCharSpecial = RegExp(/^[a-zA-Z0-9(\|)(\_)(\-)(\*)(\&)(\%)(\$)(\#)(\@)(\!)(\~)(\^)(\()(\))]+$/);
	return ( isIntCharSpecial.test(s) );
}

/**
* 判断输入变量是否包含数字或者字母
* @param {String} 要检查的变量值
* @return {bool} 是否包含数字或者字母
*/
function containIntChar( s )
{
	var containIntChar = RegExp(/[a-zA-Z0-9]+/);
	return ( containIntChar.test(s) );
}  

/**
* 判断输入变量是否包含特殊字符
* 特殊字符：~ ! @ # $ % ^ & * ( ) - _ + = [ ] { } | \ ; : ' " , . / < > ? <
* @param {String} 要检查的变量值
* @return {bool} 是否包含特殊字符
*/
function containSpecial( s )
{
	var containSpecial = RegExp(/[(\ )(\~)(\!)(\@)(\#)(\$)(\%)(\^)(\&)(\*)(\()(\))(\-)(\_)(\+)(\=)(\[)(\])(\{)(\})(\|)(\\)(\;)(\:)(\')(\")(\,)(\.)(\/)(\<)(\>)(\?)(\)]+/);
	return ( containSpecial.test(s) );
}

/**
 * 判断输入变量是否包含逗号
 * @param {String} 要检查的变量值
 * @return {bool} 是否包含特殊字符
 */
function containSpecialComma( s )
{
	var containSpecial = RegExp(/[(\,)]+/);
	return ( containSpecial.test(s) );
}

/**
* 取text域的最大输入长度
* @param {s} text对象
*/
function getByteLength(s){
	var totalLength = 0;
	var charCode;
	for(i=0;i<s.length;i++)
	{
		charCode = s.charCodeAt(i);
		if (charCode < 0x007f) {
			totalLength ++;
		} else if ((0x0080 <= charCode) && (charCode <= 0x07ff)) {
			totalLength += 2;
		} else if ((0x0800 <= charCode) && (charCode <= 0xffff)) {
			totalLength += 3;
		}
    }
	return totalLength;
}

/**
* 改变下拉列表选择项
* @param {String} select对象的ID
* @param {String} 要选中的值，必须在select的options中存在
*/
function doSelect(selectName,checkedValue)
{
	var options=document.getElementById(selectName).options;
	for(var i=0;i<options.length;i++)
	{
		var optionValue=options[i].value;
		if(optionValue==checkedValue)
		{
			options[i].selected=true;
			break;
		}
	}
}

function changeSkin(skin){
	switchType = 1;
	//换css
	$("#skincss").attr("href","resource/styles/"+skin+"/main.css");
	$("#skincss1").attr("href","resource/styles/"+skin+"/menu/menu.css");
	$("#skincss2").attr("href","resource/styles/"+skin+"/main.css");
	$("#skincss3").attr("href","resource/styles/"+skin+"/drag/inettuts.css");
	$("#skincss4").attr("href","../resource/styles/"+skin+"/detail.css");
	
	$(".c1on").removeClass('c1on').addClass("c1");
	$(".c2on").removeClass('c2on').addClass("c2");
	$(".c3on").removeClass('c3on').addClass("c3");
	$(".c4on").removeClass('c4on').addClass("c4");
	$(".c5on").removeClass('c5on').addClass("c5");
	var cur_skin = skin;
	if(cur_skin == "default") $('.c1').removeClass('c1').addClass('c1on');
	if(cur_skin == "orange") $('.c2').removeClass('c2').addClass('c2on');
	if(cur_skin == "green") $('.c3').removeClass('c3').addClass('c3on');
	if(cur_skin == "red") $('.c4').removeClass('c4').addClass('c4on');
	if(cur_skin == "gray") $('.c5').removeClass('c5').addClass('c5on');

	//刷新子iframe
	document.getElementById('tranFrame').contentWindow.location.href=
		document.getElementById('tranFrame').contentWindow.location.href;
	//	document.getElementById('tranFrame').contentWindow.location.reload();
}

$(document).ready(function(){
  $("#open").click(function(){
  $("#number").slideDown();
  });
  $("#opena").click(function(){
	  $("#numbera").slideDown();
	  });
});

/**
 * 将签名数据格式化为XML格式
 * @param arrShow   液晶屏显示数据
 * @param arrSign   签名但不显示数据
 * @returns {String}
 */
function formatXMLData(arrShow, arrSign){
	try{
		var head = '<?xml version="1.0" encoding="UTF-8"?>';
    	var str = '<T>' + '<D>';
    	for(var i=0; i<arrShow.length;i++){
    		str = str + '<M>';
    		for(var j=0; j<arrShow[i].length; j++){
    			if(j%2==1){
    				str = str + '<v>' + arrShow[i][j]+'</v>';
    			}else{
    			    str = str + '<k>' + arrShow[i][j]+'</k>';
    			}
    		}
    		str = str + '</M>';
    	}
    	
    	str = str + '</D>' + '<E>';
    	
    	for(var i=0; i<arrSign.length;i++){
    		str = str + '<M>';
    		str = str + '<k>' + '' +'</k>';
    		str = str + '<v>' + arrSign[i]+'</v>';
    		str = str + '</M>';
    	}
    	str = str + '</E>' + '</T>';
    	return head + str;
	}catch(e){

	}
}

function formatBatchXMLData(arrShow, arrSign, signArray){
	try{
		var head = '<?xml version="1.0" encoding="UTF-8"?>';
    	var str = '<T>' + '<D>';
    	for(var i=0; i<arrShow.length;i++){
    		str = str + '<M>';
    		for(var j=0; j<arrShow[i].length; j++){
    			if(j%2==1){
    				str = str + '<v>' + arrShow[i][j]+'</v>';
    			}else{
    			    str = str + '<k>' + arrShow[i][j]+'</k>';
    			}
    		}
    		str = str + '</M>';
    	}
    	
    	str = str + '</D>' + '<E>';
    	var totalNumber = signArray.length;
    	for( var i=0; i<totalNumber; i++ )
		{   
    		str = str + '<M>';
	    	str = str + '<k>' + '' + '</k>';
	    	str = str + '<v>';
			var record = signArray[i];
			for (var key in record ) 
			{
	    		str = str + '<d>' + record[key] +'</d>';
			}
			str = str + '</v>';
			str = str + '</M>';
		}
    	
    	for(var i=0; i<arrSign.length;i++){
    		str = str + '<M>';
    		str = str + '<k>' + '' +'</k>';
    		str = str + '<v>' + arrSign[i]+'</v>';
    		str = str + '</M>';
    	}
    	
    	str = str + '</E>' + '</T>';
    	
    	return head + str;
	}catch(e){
        
	}
}

/**
* 检查字符串是否为合法的手机号码7-15位数字组成
* @param {String} 字符串
* @return {bool} 是否为合法电话号码
*/
function isMobile(strText) {
	if(!isInteger(strText))
		return false;
	if(strText.length<7 || strText.length>15)
		return false;
	return true;
}

/**
* 限制上下文菜单键、刷新、后退按键。
*/
document.onkeydown = function () {
	if (event.keyCode == 93 || (event.keyCode == 8 && !needBack())) {
		event.keyCode = 0;
		return false;
	}
//	if ((event.ctrlKey)&&(event.keyCode==86)){  //屏蔽 Ctrl+V 
//		event.keyCode=0; 
//		return false;
//	} 
};


/**
* 如果当前焦点控件为text,file,password或textarea，则允许后退功能。
* @return true:需要后退功能 false:不需要后退功能
*/
function needBack() {
	
	var elem = document.activeElement;
	//alert(elem.tagName + "|" + elem.type + "|" + elem.readOnly  + "|" + elem.disabled );
	if ((elem.type == "text" || elem.type == "file" || elem.tagName == "TEXTAREA" || elem.type == "password") 
			&& elem.readOnly == false && elem.disabled == false) {
		return true;
	} else {
		return false;
	}
}

/**
* 通用打印
* @param {String} 对话框标题
* @param {String} 打印标题
* @param {String} 要打印的Div段的ID
* @param {Integer} 打印窗体的宽
* @param {Integer} 打印窗体的高
* modify by GUOYF 增加可以支持多个DIV
*/
function commonprint(titleDialog, title,divId,w,h){
	var sarg = new Array();
	sarg[0]="<br><b><font size=3>"+title+"</font></b><br><br>";
	var divIds = divId.split("#");
	var sdata;
	sarg[1] = "";
	for(var i=0;i<divIds.length;i++)
	{
		sdata=document.getElementById(divIds[i]);
		sarg[1]=sarg[1]+sdata.outerHTML;
	}
	
	openPrintDialog(titleDialog, sarg);
}

function openPrintDialog(titleDialog, data){
    try{
    	var printDialog = parent.art.dialog.open("PrintData", 
    			{id:'printDialogDiv',
    		     title: titleDialog,
    		     width: 1000,
    		     height: 500,
    		     fixed: true, 
    		     lock: true,
    		     drag: false,
    		     opacity: 0.1, 
    		     close: function () {
    		    	 
    		     }});
    	parent.art.dialog.data("titleData", data[0]);
    	parent.art.dialog.data("printDta", data[1]);
    	parent.art.dialog.data("printDialog", printDialog);
	}catch(e){}
}